package cn.edu.javaweb.userServlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.javaweb.utils.DBUtil;


@WebServlet("/ForumResponseServlet")
public class ForumResponseServlet extends HttpServlet {
	DBUtil db;
	private static final long serialVersionUID = 1L;
       
    
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
	    request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");   //不设置会乱码
		
		//获取question表的id
		String id = request.getParameter("id");
		
		db = new DBUtil();
		//查楼主的信息
		List<Map<String, String>> questionlist = db.getList("select * from question q left join user u on u.id=q.userid where q.id="+id+"");
		request.setAttribute("question", questionlist);
		System.out.println(questionlist);		
		//查看问答帖的留言
		List<Map<String, String>> responselist = db.getList("select * from response r inner join user u on r.user_id=u.id LEFT JOIN question q on r.question_id=q.id where r.question_id="+id+"");
		request.setAttribute("response", responselist);
		System.out.println(responselist);
				
		RequestDispatcher rd=request.getRequestDispatcher("volunteer/user/ForumResponse.jsp");
	    rd.forward(request, response);
	}
}
